#include <QApplication>
#include <QGraphicsView>
#include <QDebug>
#include <QVector>
#include <QSettings>

#include "configmanager.h"
#include "myscene.h"
#include "userinfodialog.h"


int main(int argc,char* argv[ ])
{
    QApplication app(argc,argv);

    // 为场景创建视图
    QGraphicsView view;

    // 创建对话框
    UserInfoDialog* dialog = new UserInfoDialog(&view);

    view.setRenderHint(QPainter::Antialiasing);
    // view.setBackgroundBrush(QPixmap(":/Sprites/Backgrounds/background_2.png"));
    view.setStyleSheet("background: rgba(0,0,0,0);border:0px;background-image: url(:/Sprites/Backgrounds/background_2.png);");

    view.setCacheMode(QGraphicsView::CacheBackground);
    view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
    // view.setDragMode(QGraphicsView::ScrollHandDrag);

    view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Card Game"));
    // scene.setForegroundBrush(QColor(255, 255, 0, 100));

    // 不能赋值但是可以引用
    ConfigManager& cm = ConfigManager::instance();
    // qDebug() << cm.screenWidth << " " << cm.screenHeight;
    view.resize(cm.screenWidth, cm.screenHeight);
    view.setSceneRect(-view.width()/2, -view.height()/2, view.width(), view.height());


    view.show();
    if(cm.nickName.isEmpty()){ // 只在用户首次使用的时候显示
        dialog->exec(); // 阻塞必须处理
    }

    // 新建场景
    MyScene scene(dialog);
    view.setScene(&scene);

    return app.exec();
}


